#include "CList.h"


//尾指针维护链表
CNode* tail = NULL;
//判空
int isEmpty() {
	return tail == NULL;
}
//尾插
void insertTail(Elemtype e)
{
	CNode * newNode = (CNode*)malloc(sizeof(CNode));
	if (newNode == NULL)
	{
		fprintf(stderr, "内存分配失败\n");
		exit(EXIT_FAILURE);
	}
	newNode->data = e;
	if (tail == NULL)
	{
		tail = newNode;
		tail->next = tail;
	}
	else
	{
		newNode->next = tail->next;
		tail->next = newNode;
		tail = newNode;	//更新尾指针
	}
}
//遍历
void traverse()
{
	if (isEmpty())
	{
		printf("链表为空。");
		return;
	}
	//从头节点开始遍历
	CNode* cur = tail->next;
	do
	{
		printf("%d ", cur->data);
		cur = cur->next;
	} while (cur != tail->next);
	printf("遍历完成，已回到头部");
}
